package com.itheima;
import java.util.ArrayList;
import  java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("张三");
        list.add("张三");

        System.out.println(list);
        System.out.println(new HashSet<String>(list));

        ArrayList<String> a = new ArrayList(new HashSet<String>(list));
        System.out.println(a);

        //1.创建HashSet集合
        HashSet<String> hashset = new HashSet<>();  //可以去除重复的数据，无序性

        //2.保存数据
        hashset.add("张");
        hashset.add("王");
        hashset.add("李");
        hashset.add("赵");
        hashset.add("张");

        HashSet<String> day = new HashSet<>();
        day.add("星期一");
        day.add("星期二");
        day.add("星期三");

        System.out.println(hashset);

        //3.取数据（迭代器）
        Iterator<String> iterator = hashset.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }

        //for(int i=0; i< hashSet.size();i++){
        // }//用不了

        //4.增强for循环
        for(String name :hashset){
            System.out.println("name="+name);
        }

        int[] m ={1,2,3,4,5};
        for (int i :m ){
            System.out.println(i);
        }

        //5.Lambda表达式
        hashset.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        day.forEach(s->  System.out.println(s));
        day.forEach(System.out::println);


        Student student = new Student("张三",26);

        System.out.println(student.toString());


    }
}
